#include "Mask.h"

#include "FaceDetector.h"
#include <QDebug>
#include <QPainter>

Mask::Mask(QObject *parent) :
    QObject(parent),
    faceDetector(new FaceDetector(1.0f))
{
}

Mask::Mask(QImage image) :
    faceDetector(new FaceDetector(1.0f)),
    mask(image)
{
    this->detectFace();

}

QImage Mask::image()
{
    return mask;
}

Face Mask::face()
{
    return maskFace;
}

void Mask::setImage(QImage image)
{
    mask = image;
    this->detectFace();
}

void Mask::detectFace()
{
    QVector<Face> faces = faceDetector->detectFaces(mask);

    if (!faces.isEmpty()) {
        maskFace = faces.last();
        if (maskFace.mouthRect().isEmpty()) {
            // Jimmer Full
            maskFace.setMouthRect(QRect(48, 132, 40, 20));
        }

//        QPainter painter(&mask);
//        painter.setPen(QPen(Qt::red));
//        painter.drawRect(maskFace.rect());
    }
}

void Mask::setFace(Face face)
{
    maskFace = face;
}
